# -*- coding: utf-8 -*-
# created on 2017/2/27

from mathsolver.functions.base import *
from mathsolver.functions.budengshi.xianxingguihua.xianxingguihua import XianXingGuiHua
from sympy import Max
from mathsolver.functions.mathematica.mathematicaSolve import MathematicaSolve


class XianXingGuiHuaExtra(BaseFunction):
    def solver(self, *args):
        eq, ineqs, variable, text = args
        assert str(eq.value[0]) == str(variable.value)
        return XianXingGuiHua().solver(ineqs, eq, text)


class OptionMaxiMize(BaseFunction):
    def solver(self, *args):
        values = args[0].sympify()
        value = Max(*values)
        self.steps.append(["答:%s" % new_latex(value), ""])
        self.output.append(BaseNumber(value))
        return self


class JieJiIsName(BaseFunction):
    def solver(self, *args):
        ineq, variable = args[:2]
        symbols = list(ineq.free_symbols())
        if len(symbols) == 1:
            answer = MathematicaSolve().solver(ineq, BaseVariable(symbols[0])).output[0].value
            key, value = list(answer.items())[0]
            self.output.append(BaseInnerSet({"name": str(variable.value), "var": key, "value": value}))
        else:
            self.output.append(BaseInnerSet({"name": str(variable.value), "var": "x", "value": ineq}))

        if self.known["inequations"]:
            self.known["inequations"].pop()
        return self


if __name__ == '__main__':
    pass
